package bible.sunflower.work.yinfeng.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CriteriaType {

	private String entity;
	
	private List<String> selectFields = new ArrayList<String>();
	
	private Map<String, Expr> exprMap = new HashMap<String, Expr>();
	
	public CriteriaType( String entity ){
		this.entity = entity;
	}
	
	public void addSelectField( String field ){
		selectFields.add( field );
	}
	
	public void addExpr(String key, Expr expr){
		exprMap.put(key, expr);
	}
	
	public Map<String, Object> getRequestParam(){
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("criteria/_entity", entity);
		for( int i = 0; i < selectFields.size(); i++ ){
			paramMap.put("criteria/_select/_field[" + (i+1) + "]", selectFields.get(i) );
		}
		int k = 1;
		for( String key : exprMap.keySet() ){
			paramMap.putAll( exprMap.get(key).getRequestParam(k) );
			k++;
		}
		return paramMap;
	}

	public List<String> getSelectFields() {
		return selectFields;
	}

	public void setSelectFields(List<String> selectFields) {
		this.selectFields = selectFields;
	}

	public Map<String, Expr> getExprMap() {
		return exprMap;
	}

	public void setExprMap(Map<String, Expr> exprMap) {
		this.exprMap = exprMap;
	}
}
